
from selenium import webdriver
import pytest

@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item,call):
    pytest_html = item.config.pluginmanager.getplugin('html')
    outcome = yield
    report = outcome.get_result()
    extra = getattr(report,'extra',[])
    if report.when == 'call':
        xfail = hasattr(report,'wasxfail')
        if (report.skipped and xfail) or (report.failed and not xfail):
            screen = t_driver.get_screenshot_as_base64()
            extra.append(pytest_html.extras.png(screen))
            extra.append(pytest_html.extras.html('<div>Additional HTML</div>'))
        report.extra = extra

@pytest.fixture(scope='session',autouse=True)
def browser():
    global t_driver
    driver = webdriver.Chrome()
    t_driver = driver
    driver.maximize_window()
    yield driver
    driver.quit()


